import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * 没有权限要求的页面
 * 可以访问所有角色
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '首页', icon: 'icon-shouye', affix: true }
      }
    ]
  },
  {
    path: '/userManagement',
    component: Layout,
    redirect: '/userManagement/userList',
    meta: { title: '用户管理', icon: 'icon-yonghuguanli' },
    children: [
      {
        path: 'userList',
        component: () => import('@/views/userManagement/userList'),
        name: 'userList',
        meta: { title: '用户管理', icon: 'icon-yonghuguanli' }
      }
    ]
  },
  {
    path: '/membershipCard',
    component: Layout,
    children: [
      {
        path: 'membershipCard',
        component: () => import('@/views/selfWash/membershipCard/membershipCard.vue'),
        name: 'MembershipCard',
        meta: { title: '会员卡管理', icon: 'icon-huiyuanqiaguanli' }
      }
    ]
  },
  {
    path: '/order',
    component: Layout,
    children: [
      {
        path: 'order',
        component: () => import('@/views/selfWash/order/order'),
        name: 'Order',
        meta: { title: '订单管理', icon: 'icon-01_dingdanguanli', noCache: true }
      }
    ]
  },
  {
    path: '/orderWriteOff',
    component: Layout,
    children: [
      {
        path: 'orderWriteOff',
        component: () => import('@/views/selfWash/orderWriteOff/orderWriteOff'),
        name: 'OrderWriteOff',
        meta: { title: '订单核销管理', icon: 'icon-xingzhuang1757', noCache: true }
      }
    ]
  },
  {
    path: '/storeManagement',
    component: Layout,
    redirect: '/storeManagement/carStore',
    meta: { title: '店铺管理', icon: 'icon-dianpu' },
    children: [
      {
        path: 'newCarShop',
        component: () => import('@/views/selfWash/storeManagement/newCarShop'),
        name: 'newCarShop',
        meta: { title: '新车店铺', icon: 'icon-cheliang-' }
      },
      {
        path: 'carStore',
        component: () => import('@/views/selfWash/storeManagement/carStore'),
        name: 'carStore',
        meta: { title: '养车店铺', icon: 'icon-baoyangjiayou' }
      },
      {
        path: 'carWashShop',
        component: () => import('@/views/selfWash/storeManagement/carWashShop'),
        name: 'carWashShop',
        meta: { title: '洗车机店铺', icon: 'icon-xiche-cuxiantiao' }
      }
    ]
  },
  {
    path: '/finance',
    component: Layout,
    redirect: '/finance/capitalFlow',
    meta: { title: '财务管理', icon: 'icon-caiwuguanli' },
    children: [
      {
        path: 'capitalFlow',
        component: () => import('@/views/finance/capitalFlow'),

        name: 'CapitalFlow',
        meta: { title: '资金流水', icon: 'icon-mingxi' }
      },
      {
        path: 'withdrawalApply',
        component: () => import('@/views/finance/withdrawalApply'),

        name: 'withdrawalApply',
        meta: { title: '申请提现列表', icon: 'icon-tixian' }
      },
      {
        path: 'withdrawalLog',
        component: () => import('@/views/finance/withdrawalLog'),

        name: 'withdrawalLog',
        meta: { title: '提现日志列表', icon: 'icon-liebiao' }
      }
    ]
  },
  {
    path: '/selfWash',
    component: Layout,
    meta: { title: '智能洗车', icon: 'icon-xiche-cuxiantiao' },
    children: [
      {
        path: 'partnerList',
        component: () => import('@/views/partnerManagement/partnerList'),
        name: 'partnerList',
        meta: { title: '合伙人管理', icon: 'icon-chengyuan' }
      },
      {
        path: 'merchant',
        component: () => import('@/views/selfWash/merchant/merchant'),
        name: 'Merchant',
        meta: { title: '商户管理', icon: 'icon-woyaotouzi00' }
      },
      {
        path: 'carWashStation',
        component: () => import('@/views/selfWash/carWashStation/carWashStation'),
        name: 'CarWashStation',
        meta: { title: '洗车站管理', icon: 'icon-bianjizhandian', noCache: true }
      },
      {
        path: 'Equipment',
        component: () => import('@/views/selfWash/equipment/equipment'),
        name: 'Equipment',
        meta: { title: '设备管理', icon: 'icon-shebei_huaban1' }
      },
      {
        path: 'repairManagement',
        component: () => import('@/views/selfWash/repairManagement/repairManagement'),
        name: 'RepairManagement',
        meta: { title: '报修管理', icon: 'icon-baoxiu-xuanzhong', noCache: true }
      },
      {
        path: 'subAccountList',
        component: () => import('@/views/partnerManagement/subAccountList'),
        name: 'subAccountList',
        hidden: true,
        meta: { title: '子账号管理', icon: 'icon-chengyuan' }
      },
      {
        path: 'investmentReturns',
        component: () => import('@/views/selfWash/investmentReturns/costmanagement'),
        name: 'costmanagement',
        meta: { title: '投入回本管理', icon: 'icon-touzi' }
      }, {
        path: 'inputretunrdetails',
        component: () => import('@/views/selfWash/investmentReturns/basicsdetails'),
        name: 'basicsdetails',
        hidden: true,
        meta: { title: '投入基建详情', icon: 'icon-touzi' }
      }, {
        path: 'inpequipmentdetails',
        component: () => import('@/views/selfWash/investmentReturns/devicedetails'),
        name: 'devicedetails',
        hidden: true,
        meta: { title: '投入设备详情', icon: 'icon-touzi' }
      }
    ]
  }, {
    path: '/newCar',
    component: Layout,
    alwaysShow: true,
    meta: { title: '新车管理', icon: 'icon-xiche-cuxiantiao' },
    children: [
      {
        path: 'newCarInvoice',
        component: () => import('@/views/newCar/invoice/newCarInvoice'),
        name: 'newCarInvoice',
        meta: { title: '新车发票审核', icon: 'icon-fapiaoguanli' }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = []

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
